﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CashierSystem.UserManager;
using CashierSystem.CashierInManager;

namespace CashierSystem.UserManager
{
    public partial class UserManagerForm : Form
    {
        public UserManagerForm()
        {
            InitializeComponent();
        }

        string[] roleId;
        string[] roleName;
        string[] departId;
        string[] departName;

        private void UserManagerForm_Load(object sender, EventArgs e)
        {
            UserManagerAction.getUserList(lv1);
            UserManagerAction.getRoleInfo(out roleId, out roleName);
            cbRole.Items.Clear();
            for (int i = 0; i < roleId.Length; i++)
            {
                cbRole.Items.Add(roleName[i]);
            }
            CashierInManager.CashierInManager.getDepartInfo(out departName, out departId);
            cbDepart.Items.Clear();
            for (int i = 0; i < departId.Length; i++)
            {
                cbDepart.Items.Add(departName[i]);
            }
                

        }


        private void button1_Click(object sender, EventArgs e)
        {
            string accountId = tbAccountId.Text;
            string password = tbPassword.Text;
            string userName = tbUserName.Text;
            int j = cbDepart.SelectedIndex;
            string departId1 = departId[j];
            int i = cbRole.SelectedIndex;
            string roleId1 = roleId[i]; 
            UserManagerAction.addUser(accountId, userName, password,departId1);
            UserManagerAction.addUserRole(accountId, roleId1);

            ListViewItem item = new ListViewItem();
            item.SubItems[0].Text = accountId;
            item.SubItems.Add(userName);
            lv1.Items.Add(item);


            DialogResult response = MessageBox.Show("添加成功！");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string accountId = lv1.SelectedItems[0].SubItems[0].Text;
            UserManagerAction.deleteUser(accountId);
            DialogResult response = MessageBox.Show("删除成功！");
            UserManagerAction.getUserList(lv1);
        }
    }
}